package com.bionic.banking.commands;

import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;

public class ControllerHelper {

    private static ControllerHelper instance = null;
    HashMap<String, ICommand> commands = new HashMap<>();

    public ControllerHelper() {
        commands.put("login", new CommandLogin());
        commands.put("logout", new CommandLogout());        
        commands.put("viewMyProfile", new CommandViewMyProfile());
        
        commands.put("startCreateCustomer", new CommandStartCreateCustomer());
        commands.put("startCreateBankAccount", new CommandStartCreateBankAccount());
        commands.put("startCreateBankOperation", new CommandStartCreateBankTransaction());

        commands.put("startEditCustomer", new CommandStartEditCustomer());
        commands.put("startEditBankAccount", new CommandStartEditBankAccount());
        
        commands.put("viewBankTransaction", new CommandViewBankTransaction());
        
        commands.put("createCustomer", new CommandCreateCustomer());
        commands.put("createBankAccount", new CommandCreateBankAccount());
        commands.put("createBankOperation", new CommandCreateBankOperation());         
        
        commands.put("viewCustomersList", new CommandViewCustomersList());                
        commands.put("viewBankAccountsList", new CommandViewBankAccountsList());        
        commands.put("viewTransactionsList", new CommandViewBankTransactionsList()); 
        
        //commands.put("loadphoto", new CommandLoadPhoto());         
        commands.put("returnToMain", new CommandReturn()); 
    }

    public ICommand getCommand(HttpServletRequest request) {
        ICommand command = commands.get(request.getParameter("command"));
        if (command == null) {
            command = new CommandMissingException();
        }
        return command;
    }

    public static ControllerHelper getInstance() {
        if (instance == null) {
            instance = new ControllerHelper();
        }
        return instance;
    }
}
